/*
 * Copyright (c) 2017, Iotelligent Corporation
 * All rights reserved.
 *
 * Description:
 *
 *   Common configuration which contains:
 *   - Macros definitions of firmware features
 *     a. Debug message level;
 *     b. Macro flags for function test;
 *   - Board-level definitions
 */

#ifndef __CONFIG_H__
#define __CONFIG_H__

#include "ibat2000_conf.h"

/************************* Firmware features **********************************/
/*
 * Uncomment the line below to expanse the "assert_param" macro in
 * the Standard Peripheral Library drivers code.
 */
// #define USE_FULL_ASSERT

/* Uncomment this line to enable verbose debug output */
#define DEBUG_OUTPUT            1
#define DEBUG_MAIN_UART_OUTPUT  0

/* Module test flag */
#if 0
    #define TEST_UART_MODULE        1
    #define TEST_TIMER_MODULE       1
    #define TEST_PMIC_MODULE        1
#endif

/* Chip info */
#define CHIP_MODEL              "iBAT2000"
#define CHIP_CLK                "96 MHZ"
#define CHIP_IRAM               "128 KB"
#define CHIP_DRAM               "32 KB"

/* temperature sense timer value 10s */
#define TIMER_SW_TEMP_VALUE     10000

/* sleep timer value 30s */
#define TIMER_SW_SLEEP_VALUE    30000

/* power working mode */
#define POWER_IDLE_MODE         1


/************************* Board-level definitions ****************************/
/* RF link parameters and board-level config */
typedef struct
{
    /*************************** module info **********************************/
    /* Module serial number */
    uint32_t serial_number;
    /* Module address */
    uint16_t module_addr;

    /*************************** calibration params ***************************/
    /* Corrected value of chip tx dc offset */
    uint32_t tx_dc_offset;
    /* Corrected value for Forward power measurement (dB) */
    float tx_power_delta;
    /* Corrected value for RxIN power measurement (dB) */
    float rx_power_delta;

    /*************************** rf output power ******************************/
    /* RF carrier status (0: Off, 1: On) */
    uint8_t carrier_en;
    /* External PA status (0: Disable, 1: Enable) */
    uint8_t pa_en;
    /* External PA bias voltage (0 ~ 3000 mV) */
    uint16_t pa_bias;
    /* Tx output power (dBm) */
    uint8_t tx_power;
    /* Tx gain control */
    uint16_t tx_gain;

    /*************************** rf antenna control ***************************/
    /* Antenna returnloss threshold (dB) */
    uint8_t ant_rl_thr;
    /* Antenna auto switch mode (0: Disable, 1: Enable) */
    uint8_t ant_switch_en;
    /* Antenna attached status */
    uint8_t ant_status;
    /* Current working antenna idx (0: ANT-1 ~ 3: ANT-4, 0xf0: Not avaliable) */
    uint8_t ant_curr_idx;
    /* Antenna switch interval */
    uint16_t ant_switch_interval;

    /*************************** rf hopping control ***************************/
    /* RF regulatory region */
    uint8_t rf_region;
    /* RF working frequency (KHz) */
    uint32_t rf_channel;
    /* RF hopping mode (0: Disable, 1: Enable) */
    uint8_t fhss_en;
    /* RF hopping interval (10 ~ 65535 ms) */
    uint16_t fhss_interval;

    /*************************** rf modulation control ************************/
    /* R=>T modulation type (0: DSB-ASK, 1: SSB-ASK, 2: PR-ASK) */
    uint8_t mod_type;
    /* R=>T modulation depth (30: 30% ~ 100: 100%) */
    uint8_t mod_depth;

    /*************************** rf link parameters ***************************/
    /* RFID Protocol (0: EPC/18K-6C, 1: GB, 2: GJB) */
    uint8_t protocol;

    /* EPC/18K-6C - R=>T link profile (7: 128k, 11: 320k, 14: 64k, 8: 160k */
    uint8_t epc_link_profile;
    /* EPC/18K-6C - R=>T Tari value (0: 6.25us, 1: 12.5us, 2: 25us) - RFU */
    uint8_t epc_tari;
    /* EPC/18K-6C - R=>T RTcal value (ns) - RFU */
    uint32_t epc_rtcal;
    /* EPC/18K-6C - R=>T TRcal value (ns) - RFU */
    uint32_t epc_trcal;
    /* EPC/18K-6C - R=>T divide ratio (0: 8, 1: 64/3) */
    uint8_t epc_dr;
    /* EPC/18K-6C - T=>R link frequency - RFU */
    uint8_t epc_blf;

    /* GB/GJB R=>T Tc value (0: 6.25us, 1: 12.5us) */
    uint8_t gb_tc;
    /* GB T=>R link frequency */
    uint8_t gb_blf;
    /* GJB T=>R link frequency */
    uint8_t gjb_blf;

    /* T=>R data encoding (0: FM0, 1: M2, 2: M4, 3: M8) */
    uint8_t data_encode;
    /* T=>R extended preamble */
    uint8_t trext;

    /*************************** protocol parameters **************************/
    /* EPC/18K-6C - anti-collision algorithm (0: Fixed-Q, 1: Dynamic-Q) */
    uint8_t dynamic_q_en;
    /* EPC/18K-6C - Q value for Fixed-Q algorithm */
    uint8_t q_val;
    /* EPC/18K-6C - Default Q value for Dynamic-Q algorithm */
    uint8_t dynamic_default_q_val;
    /* EPC/18K-6C - Min Q value for Dynamic-Q algorithm */
    uint8_t dynamic_min_q_val;
    /* EPC/18K-6C - Max Q value for Dynamic-Q algorithm */
    uint8_t dynamic_max_q_val;

    /*************************** firmware features ****************************/
    /* The idle timeout for system entring low power mode (ms) */
    uint32_t sleep_timeout;
} param_cfg_t;

extern const uint8_t fw_version[], build_date[], build_time[];
extern const uint32_t build_revision;
extern uint8_t boot_mode;
extern param_cfg_t g_RfPara;

int board_rf_init( void );
int rf_para_init( void );
void board_info( void );

#endif /* __CONFIG_H__ */

